﻿using Microsoft.Extensions.Logging;
using MyWeb.Extensions.RabbitMQ.Model;
using MyWeb.Extensions.RabbitMQ.ReadMqConfig;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWeb.Extensions.RabbitMQ.ReadMqConfig
{
    internal class ReadMqConfigHelper
    {

        private readonly ILogger<ReadMqConfigHelper> _logger;
        public ReadMqConfigHelper(ILogger<ReadMqConfigHelper> logger)
        {
            _logger = logger;
        }
        /// <summary>
        /// 读取配置文件
        /// </summary>
        /// <returns></returns>
        public List<MqConfigInfo>? ReadMqConfig()
        {
            try
            {
                //List<MqConfigInfo> config = AppHelper.ReadAppSettings<MqConfigInfo>(new string[] { "MQ" }); // 读取MQ配置信息

                List<MqConfigInfo> config = new List<MqConfigInfo>();
                MqConfigInfo configInfo = new MqConfigInfo();
                configInfo.Host = "127.0.0.1";
                configInfo.Port = 5672;
                configInfo.User = "admin";
                configInfo.Password = "123456";
                configInfo.ExchangeName = "ExchangeName_Demo";
                configInfo.Durable = true;
                config.Add(configInfo);

                if (config.Any())
                {
                    return config;
                }
                _logger.LogError($"获取MQ配置信息失败：没有可用数据集");
                return null;
            }
            catch (Exception ex)
            {
                _logger.LogError($"获取MQ配置信息失败：{ex.Message}");
                return null;
            }
        }

    }
}
